package ControlLayer;
import java.util.ArrayList;
import ModelLayer.Person;
import ModelLayer.Loan;
import ModelLayer.LoanCollections;
import ModelLayer.DVD;
import ModelLayer.Copy;


/**
 * Write a description of class LoanCtr here.
 * 
 * @author Gruppe A 
 * @version 1.0
 */
public class LoanCtr
{
    private LoanCollections lc;
    

    /**
     * Constructor for objects of class LoanCtr
     */
    public LoanCtr()
    {
        lc = LoanCollections.getInstance();
        
    }

    /**
     * A method that executes the existing findLoan method in our LoanCollections.
     * @param long id
     */
    public Loan findLoan(long id)
    {
        return lc.findLoan(id);
    }
    
    /**
     * A method that creates a new loan, it takes a few parameters, and then afterwards adds it to
     * our LoanCollections
     * @param String deliveryDate
     * @param Person person
     * @param long id
     */
    public void createLoan(int deliveryDateMonth, int deliveryDateDay, Person loanperson, long id)
    {
        Loan l = new Loan(deliveryDateMonth, deliveryDateDay, loanperson, id);
        lc.addLoan(l);
        
    }
    
    /**
     * A method for updating loan, it uses an id number to find the correct loan and the executes the
     * update command
     * @param long id
     * @param String home
     * @param String deliveryDate
     */
    public void updateLoan(long id, String home, int deliveryDateMonth, int deliveryDateDay)
    {
        Loan l = lc.findLoan(id);
        lc.updateLoan(l, deliveryDateMonth, deliveryDateDay, home);
                
    }
    
    /**
     * A method for adding a copy to our collection.
     * @param DVD d
     * @param long serialnr
     * @param long id
     */
    public void addCopy(DVD d, long serialnr, long id)
    {
        lc.addCopy(d, serialnr, id);
    }
    
    /**
     * A method that makes a loans status become returned.
     * @param Loan loan
     */
    public void returned(Loan loan)
    {
        lc.returnLoan(loan);
    }
    
    /**
     * A method that shows the status of a loan
     * @param long id
     */
    public boolean getStatus(long id)
    {
        return lc.getStatus(id);
    }
    
    /**
     * A method that executes the existing method in LoanCollections to show all loans
     * @return ArrayList alloans
     */
    public ArrayList listAllLoans()
    {
        
        return lc.listAllLoans();
    }
}
